@extends('adminDialog')

@section('content')
    <form action="{{url('admin/agents/subupdate',['id'=>$model->id,'parent_id'=>$model->parent_id])}}" method="POST" class="J_ajaxForm">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <div class="pop_cont pop_table">
            <table width="100%">
                <tbody>
                <tr>
                    <th><label for="name">账号 <span class="red">*</span></label></th>
                    <td>
                        <input type="text" name="user[name]" id="name" class="input length_2" value="{{$model->name}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="password">密码 @if (!$model->id) <span class="red">*</span>@endif</label></th>
                    <td>
                        <input type="password" name="user[password]" id="password" class="input length_2" value=""/>
                        @if ($model->id)
                            <div class="cc gray" style="display: inline-block;">不修改请留空</div>
                        @endif
                    </td>
                </tr>
                <tr>
                    <th><label for="pay_password">支付密码 @if (!$model->id) <span class="red">*</span>@endif</label></th>
                    <td>
                        <input type="password" name="user[pay_password]" id="pay_password" class="input length_2" value=""/>
                        @if ($model->id)
                            <div class="cc gray" style="display: inline-block;">不修改请留空</div>
                        @endif
                    </td>
                </tr>
                <tr>
                    <th><label for="avatar">头像 </label></th>
                    <td>
                        <input type="hidden" name="user[avatar_id]" id="avatar_id" value="{{$model->avatar_id}}"/>
                        <span id="upload_btn" class="cc"><img src="{{url('/img/avatar-'.intval($model->avatar_id).'/80-80')}}"</span>
                        <div class="cc gray">建议 100px * 100px</div>
                    </td>
                </tr>
                <tr>
                    <th><label for="nick">昵称 <span class="red">*</span></label></th>
                    <td>
                        <input type="text" name="user[nick]" id="nick" class="input length_2" value="{{$model->nick}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="real_name">姓名</label></th>
                    <td>
                        <input type="text" name="user[real_name]" id="real_name" class="input length_2" value="{{$model->real_name}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="email">E-Mail</label></th>
                    <td>
                        <input type="text" name="user[email]" id="email" class="input length_3" value="{{$model->email}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="prov_id">所在区域 <span class="red">*</span></label></th>
                    <td>
                        <select name="agents[prov_id]" id="prov_id">
                            <option value="">请选择</option>
                            @foreach($provinces as $pro)
                                <option @if($agents_model['prov_id'] == $pro->id) selected @endif  value="{{$pro->id}}">{{$pro->name}}</option>
                            @endforeach
                        </select>
                        -
                        <select name="agents[city_id]" id="city_id">
                            <option value="">请选择</option>
                            @foreach($cities as $pro)
                                <option @if($agents_model['city_id'] == $pro->id) selected @endif  value="{{$pro->id}}">{{$pro->name}}</option>
                            @endforeach
                        </select>
                        -
                        <select name="agents[area_id]" id="area_id">
                            <option value="">请选择</option>
                            @foreach($areas as $pro)
                                <option @if($agents_model['area_id'] == $pro->id) selected @endif value="{{$pro->id}}">{{$pro->name}}</option>
                            @endforeach
                        </select>
                    </td>
                </tr>
                <tr>
                    <th><label for="status">状态</label></th>
                    <td>
                        <input type="radio" @if($model->status) checked="checked" @endif name="user[status]" value="1" id="status_1"/><label for="status_1">启用</label>
                        <input type="radio" @if(!$model->status) checked="checked" @endif name="user[status]" value="0" id="status_2"/><label for="status_2">禁用</label>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>

        <div class="pop_bottom cc">
            <button type="reset" class="btn fr" id="J_dialog_close">取消</button>
            <button type="submit" class="btn btn_submit J_ajax_submit_btn fr mr10" id="J_dialog_close">提交</button>
        </div>
    </form>
@stop

@section('style')
    <style>
        .body_none {width: 500px;}
        #upload_btn {cursor:pointer; display: inline-block;}
        #upload_btn img {border-radius: 50%;}
    </style>
@stop

@section('js')
    @parent
    <script src="{{asset('/js/admin/admin.js')}}"></script>
    <script src="{{asset('/js/plupload/plupload.full.min.js')}}"></script>
    <script>
        var uploader = new plupload.Uploader({
            browse_button : 'upload_btn',
            url : '{{url('/upimg')}}',
            flash_swf_url : '{{asset('/js/plupload/Moxie.swf')}}',
            silverlight_xap_url: '{{asset('/js/plupload/Moxie.xap')}}',
            filters : {
                mime_types : [
                    {title: '图片文件', extensions: "jpg,gif,png"}
                ],
                max_file_size: '10mb'
            },
            multi_selection : false,
            file_data_name  : 'file',
            multipart_params: {'_token': GV.TOKEN, 'dir': 'avatar'}
        });
        uploader.init();

        uploader.bind('Error', function (uploader, errObject) {
            Wind.dialog.alert(errObject.message);
        });

        uploader.bind('FilesAdded', function (uploader, files) {
            uploader.start();
        });
        uploader.bind('FileUploaded', function (uploader, file, responseObj) {
            var ret = $.parseJSON(responseObj.response);
            if (! ret.id)
                Wind.dialog.alert(ret.message);
            else {
                $('#avatar_id').val(ret.id);
                $('#upload_btn').find('img').attr('src', '{!! url("img/avatar-' + ret.id + '/80-80") !!}');
            }
        });
        $('#prov_id').on('change',function(){
            reloadOptions($(this).val(),$('#city_id'),'Area','','',$('#area_id'));
        });

        $('#city_id').on('change',function(){
            reloadOptions($(this).val(),$('#area_id'),'Area');
        });
    </script>
@stop